package com.ssy.lingxi.settle.accounts.controller.mobile;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.dto.request.InvoiceMessageAddRequest;
import com.ssy.lingxi.dto.request.InvoiceMessageDeleteRequest;
import com.ssy.lingxi.dto.request.InvoiceMessageGetRequest;
import com.ssy.lingxi.dto.request.InvoiceMessageUpdateRequest;
import com.ssy.lingxi.dto.response.InvoiceMessageResponse;
import com.ssy.lingxi.settle.accounts.service.InvoiceMessageService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * @menu App - 会员发票相关接口
 * @author 伍将
 * @date 2020/12/30
 **/
@RestController
@RequestMapping("/settle/accounts/mobile")
public class MobileInvoiceMessageController extends BaseController {

    @Resource
    InvoiceMessageService invoiceMessageService;

    /**
     * 查询发票列表
     * @author 伍将
     * @date 2020/12/30
     **/
    @RequestMapping(value = "/invoice/message/list", method = RequestMethod.GET)
    public Wrapper<List<InvoiceMessageResponse>> invoiceMessageList(HttpServletRequest request) {
        UserLoginCacheDTO sysUser = this.getSysUser(request);
        return invoiceMessageService.invoiceMessageList(sysUser);
    }

    /**
     * 查询发票详情
     * @author 伍将
     * @date 2020/12/30
     **/
    @RequestMapping(value = "/invoice/message/details", method = RequestMethod.GET)
    public Wrapper<InvoiceMessageResponse> invoiceMessageDetails(@Valid InvoiceMessageDeleteRequest request) {
        return invoiceMessageService.invoiceMessageDetails(request);
    }

    /**
     * 新增发票
     * @author 伍将
     * @date 2020/12/30
     **/
    @RequestMapping(value = "/invoice/message/add", method = RequestMethod.POST)
    public Wrapper<Void> invoiceMessageAdd(@Valid @RequestBody InvoiceMessageAddRequest request, HttpServletRequest httpServletRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser(httpServletRequest);
        return invoiceMessageService.invoiceMessageAdd(request, sysUser);
    }

    /**
     * 修改发票
     * @author 伍将
     * @date 2020/12/30
     **/
    @RequestMapping(value = "/invoice/message/update", method = RequestMethod.POST)
    public Wrapper<Void> invoiceMessageUpdate(@Valid @RequestBody InvoiceMessageUpdateRequest request, HttpServletRequest httpServletRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser(httpServletRequest);
        return invoiceMessageService.invoiceMessageUpdate(request, sysUser);
    }

    /**
     * 删除发票
     * @author 伍将
     * @date 2020/12/30
     **/
    @RequestMapping(value = "/invoice/message/delete", method = RequestMethod.POST)
    public Wrapper<Void> invoiceMessageDelete(@Valid @RequestBody InvoiceMessageDeleteRequest request, HttpServletRequest httpServletRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser(httpServletRequest);
        return invoiceMessageService.invoiceMessageDelete(request, sysUser);
    }

    /**
     * 获取默认发票
     * @author 伍将
     * @date 2021/2/4
     **/
    @RequestMapping(value = "/invoice/message/getDefaultInvoice", method = RequestMethod.GET)
    public Wrapper<InvoiceMessageResponse> getDefaultInvoice(@Valid InvoiceMessageGetRequest request) {
        return invoiceMessageService.getDefaultInvoice(request);
    }
}
